package Z_directExchange;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import utils.RabbitMQUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @author： pang-yun
 * @date： 2021-12-15 19:37
 * 功能目的 ：用于  消费
 */

public class DirectProducer {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 获取信道
        Channel channel = RabbitMQUtils.getChannel();
        // 声明交换机 以及模式
        channel.exchangeDeclare(Const.EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        //------------------------------------------------------------
        // 发送消息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String next = scanner.next();
            channel.basicPublish(Const.EXCHANGE_NAME, Const.ROUTE_KEY, null, next.getBytes(StandardCharsets.UTF_8));
            channel.basicPublish(Const.EXCHANGE_NAME, Const.ROUTE_KEY_A, null, next.getBytes(StandardCharsets.UTF_8));
            channel.basicPublish(Const.EXCHANGE_NAME, Const.ROUTE_KEY_C, null, next.getBytes(StandardCharsets.UTF_8));
            System.out.println("message :" + next.toString() + "已经发送");
        }

    }
}
